package com.sky.controller.User;

import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("usersetmealcontroller")
@Slf4j
@RequestMapping("/user/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类id查询套餐集合 只查询在售状态下的套餐 条件查询
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    //开启spring cache缓存
    @Cacheable(cacheNames = "setmeal",key = "#categoryId")
    public Result<List<SetmealVO>> getByCategoryIdList(Long categoryId){
        log.info("前端传过来的分类id为:{}",categoryId);
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);
      List<SetmealVO> setmealVOList =  setmealService.getByCategoryIdList(setmeal);
        return Result.success(setmealVOList);
    }

    /**
     * 根据套餐id查询所有的菜品
     * @return
     */
    @GetMapping("/dish/{id}")
   // @Cacheable(cacheNames = "setmeal",key = "#id")
    public Result<List<DishItemVO>> getBySetmealIdDish(@PathVariable Integer id){
        log.info("前端传过来的套餐id为:{}",id);
       List<DishItemVO> dishItemVOList =  setmealService.getBySetmealIdDish(id);
        return Result.success(dishItemVOList);
    }
}
